package com.luoxiang.socialandroid.fragment;

import static com.luoxiang.socialandroid.common.Constants.MmkvConst.DOMAIN;

import com.bumptech.glide.Glide;
import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.base.LazyLoadFragment;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class GetImageFragment extends LazyLoadFragment {
    private SubsamplingScaleImageView imageView;
    private String getImage;

    @Override
    protected int setContentView() {
        return R.layout.fragment_getimage;
    }

    @Override
    protected void initView() {
        imageView = findViewById(R.id.imageView);
        getImage = getArguments().getString("getImage");

        Observable.fromCallable(() ->
                        Glide.with(getContext())
                                .asBitmap()
                                .load(DOMAIN + getImage)
                                .submit()
                                .get()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                .subscribe(bitmap -> {
                    imageView.setImage(ImageSource.bitmap(bitmap));
                });


    }

    @Override
    protected void lazyLoad() {

    }
}
